/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

//题目链接：https://leetcode.cn/problems/n-ary-tree-level-order-traversal/


class Solution
{
public:
    // 层序遍历，队列模拟
    vector<vector<int>> levelOrder(Node *root)
    {
        vector<vector<int>> ret;
        queue<Node *> q;
        if (root == nullptr)
            return ret;
        q.push(root);
        while (q.size()) // 直到队列为空
        {
            vector<int> tmp;   // 每一层的节点内数据
            int sz = q.size(); // 记录当前层节点个数
            while (sz--)       // 将一层的节点其孩子节点全部入队列
            {
                Node *t = q.front();
                tmp.push_back(t->val); // 记录当前层的数据
                q.pop();
                for (Node *child : t->children)
                {
                    q.push(child);
                }
            }
            ret.push_back(tmp);
        }
        return ret;
    }
};